 package com.yytek.am.core;
 import akka.actor.ActorSystem;
 import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import scala.concurrent.duration.Duration;
 import scala.concurrent.duration.FiniteDuration;

 import java.util.concurrent.TimeUnit;

 public class ActorConfig {
      /** The conf. */
      private static Config conf = null;
      private static String ACTOR_SYSTEM="yytek-am-engine";
      /** The actor system. */
      private static ActorSystem actorSystem = null;

      /** The logger. */
      private static Logger logger = LoggerFactory.getLogger(ActorConfig.class);
      static {

          // load default
          conf = ConfigFactory.load("akka.conf");
          logger.debug("Load Actor config {}", conf.toString());
          actorSystem = ActorSystem.create(ACTOR_SYSTEM, conf);

      }

      /**
       * Create and get actor system.
       *
       * @return the actor system
       */
      public static ActorSystem createAndGetActorSystem() {
          if (actorSystem == null ) {
              actorSystem = ActorSystem.create(ACTOR_SYSTEM, conf);
          }
          return actorSystem;
      }


      /** The Constant timeOutDuration. */
      // wait for 10 seconds
      public static final FiniteDuration timeOutDuration = Duration.create(10,
              TimeUnit.SECONDS);

      /**
       * Shut down actor system force.
       */
      public static void shutDownActorSystemForce() {
          if (actorSystem!=null) {
              logger.info("shutting down actor system...");
              actorSystem.terminate().value().get();
              logger.info("Actor system has been shut down.");
          } else {
              logger.info("Actor system has been terminated already. NO OP.");
          }

      }




      /**
       * Gets the timeoutduration.
       *
       * @return the timeoutduration
       */
      public static FiniteDuration getTimeoutduration() {
          return timeOutDuration;
      }

 }
